import xml.etree.ElementTree as ET

# 比较两个元素
def compare_elements(elem1, elem2, path=''):
    # 比较标签
    if elem1.tag != elem2.tag:
        print(f"路径 {path} 的标签不匹配: '{elem1.tag}' 和 '{elem2.tag}'")
    # 比较文本，同时检查None
    elif (elem1.text is None and elem2.text is not None) or \
         (elem1.text is not None and elem2.text is None) or \
         (elem1.text is not None and elem2.text is not None and elem1.text.strip() != elem2.text.strip()):
        text1 = elem1.text.strip() if elem1.text is not None else None
        text2 = elem2.text.strip() if elem2.text is not None else None
        print(f"路径 {path} 的文本不匹配: '{text1}' 和 '{text2}'")
    # 比较属性
    elif elem1.attrib != elem2.attrib:
        print(f"路径 {path} 的属性不匹配: {elem1.attrib} 和 {elem2.attrib}")
    else:
        # 比较子元素
        children1 = list(elem1)
        children2 = list(elem2)
        if len(children1) != len(children2):
            print(f"路径 {path} 的子元素数量不匹配")
        for child1, child2 in zip(children1, children2):
            compare_elements(child1, child2, path=f"{path}/{child1.tag}")

# 比较两个XML文件
def compare_xml_files(file1, file2):
    tree1 = ET.parse(file1)
    tree2 = ET.parse(file2)
    compare_elements(tree1.getroot(), tree2.getroot())

# 替换 'file1.xml' 和 'file2.xml' 为你实际的文件名
compare_xml_files('33332.xml', '22365.xml')